<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/8/17 Time: 11:25
 */

namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Lib\Utils\Captcha;
use App\Traits\ApiRespond;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{
    use ApiRespond;

    /**
     * 获取验证码图片
     * @param Captcha $captcha
     * @param string $type
     * @param $uuid
     * @return mixed
     */
    public function image(Captcha $captcha, $uuid, $type = 'default')
    {
        return $captcha->createById($uuid, $type);
    }

    /**
     *
     * 获取验证码
     * @author Paco
     * @createTime 2018/8/17 11:35
     * @param Request $request
     * @param string $type
     * @return mixed
     */
    public function info(Request $request, $type = 'default')
    {
        $url = substr(str_replace($request->decodedPath(), '', $request->url()), 0, -1);
        $uuid = uuid();
        $data = [
            'url' => $url . '/api/captcha/image/' . $type . '/' . $uuid,
            'uuid' => (string)$uuid
        ];
        return $this->respondWith($data);
    }


}